/**
 *
 * @author Valdez
 */

import java.util.HashMap;

public class Funcion {
    String name;
    String[] keys;
    HashMap parametros;
    List expresion;
    String[] body; 
    
    public Funcion(String[] declaracion, String[] cuerpo){
        name = declaracion[0];
        parametros = new HashMap();
        keys = new String[declaracion.length-3];
        for (int i = 2; i<declaracion.length-3; i++){
            parametros.put(declaracion[i], null);
            keys[i] = declaracion[i];
        }
        body=cuerpo;
        
    }
    public String llamarFuncion(String[] paramactuales, HashMap func){
        if(keys.length==paramactuales.length){
            for(int i=0; i< keys.length;i++){
                   parametros.remove(keys[i]);
                   parametros.put(keys[i], paramactuales[i]);
                   System.out.println(""+paramactuales[i]);
            }
        }
        for(int i=0;i<body.length;i++){
            if(parametros.containsKey(body[i]))
                body[i]=(String)parametros.get(body[i]);
        }
        expresion = new List(body, func);
        return expresion.evaluar();
    }
    
    public List getList(){
        return expresion;
    }
    
    public HashMap getParametros(){
        return parametros;
    }
    
    public String getName(){
        return name;
    }
    
    public int getKeysLength(){
        return keys.length;
    }
    
}
